<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/5/10
 * Time: 9:02
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\api\controller\v1;

use app\common\lib\Show;
use app\common\lib\Status;
use app\common\model\WeixinExpress;
use app\common\model\WeixinExpressConfig;
use app\common\model\WeixinExpressTag;

class Express extends Base
{
    /**
     * @return array|\think\response\Json
     * @throws \think\Exception
     */
    public function getExpressConfigInfo()
    {
        $config = (new WeixinExpressConfig())->getBaseById(1);
        if (empty($config)) {
            return Show::json_show(Status::mini_error, "配置错误");
        }
        $config['description'] = htmlspecialchars_decode($config['description']);
        $config['exemption'] = htmlspecialchars_decode($config['exemption']);
        //获取剩余次数
        $express = (new WeixinExpress())->getUserExpressSurplus($this->m_openid);
        $express_config = (new WeixinExpressConfig())->getBaseById(1);
        $list_header = (new WeixinExpressTag())->getBaseByListAll(["status"=>Status::mysql_normal]);
        return Show::json_show(Status::mini_normal, "ok", [
            "config"=>$config,
            "number"=>$express,
            "price"=>$express_config['price'] ?? 0,
            "list_header"=>$list_header ?? []
        ]);
    }
}